package service;

import mapper.FuncMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import po.Func;
import po.FuncCustom;
import po.Result;

import java.util.List;

@Service
public class FuncServiceImpl implements FuncService {

    @Autowired
    private FuncMapper funcMapper;

    @Override
    public List<FuncCustom> findAllFuncCustom(FuncCustom funcCustom) throws Exception {
        return funcMapper.findAllFuncCustom(funcCustom);
    }

    @Override
    public Result addFunc(Func func) {
        Result result = new Result();
        try {
            funcMapper.addFunc(func);
        } catch (Exception e) {
            result.setResult("fail");
            result.setMessage("添加失败！");
            return result;
        }
        result.setResult("success");
        result.setMessage("添加成功！");
        return result;
    }

    @Override
    public Result deleteFuncById(int id) {
        Result result = new Result();
        try {
            funcMapper.deleteFuncById(id);
        } catch (Exception e) {
            result.setResult("fail");
            result.setMessage("删除失败！");
            return result;
        }
        result.setResult("success");
        result.setMessage("删除成功！");
        return result;
    }

    @Override
    public Result updateFuncById(int id, Func func) {
        Result result = new Result();
        try {
            func.setId(id);
            funcMapper.updateFuncById(func);
        } catch (Exception e) {
            result.setResult("fail");
            result.setMessage("修改失败！");
            return result;
        }
        result.setResult("success");
        result.setMessage("修改成功！");
        return result;
    }
}
